Blueprint Help Send comments on this topic.
Data Records

Glossary Item Box

In the examples below the 'black' code is auto-generated by the translator, whilst the 'red' code is the additional example code.

 

DtypeRec.hpp (no changes required)

class DtypeRec : public DtypeRecBase
{
public:
}; 

 

Dtype.hpp

#define MAX_X 100

class Dtype : public ClpNewObject
{
private:
   // TODO: Add custom data member variables
   Uns   mN;
   Float mX[MAX_X];

public:
   // Initializes this data structure
   // returns TRUE if successful, FALSE otherwise
   Uns Initialise()
   {
      mN = 0;

      for ( Uns i = 0; i < MAX_X; ++i )
         mX[i] = 0;

      return TRUE;
   }

   // TODO: Add custom data access functions
   Uns    GetN(){ return mN; }
   void   SetN( Uns N ){ mN = N; }

   Float* GetX(){ return mX; }
   Float  GetXi( Uns Idx ){ return mX[Idx]; }
   void   SetXi( Uns Idx, Float Xi ){ mX[Idx] = Xi; }  

   Uns&   N(){ return mN; }
   Float* X(){ return mX; }
   Float& X( Uns Idx ){ return mX[Idx]; }

   Uns    NumX(){ return MAX_X; }
};

 

This example shows two types of data access functions:

  1. Explicit Get/Set functions, which return/set data by value
  2. Generic access functions, which return data by reference/pointer

Either is suitable depending on local coding standards, but both are rarely required.

It is also good practice to have functions that return the size of any arrays, as this hides the definition of the size, and thus requires less code changes if the data structure changes. This is particularly important for variable sized arrays. See Data Components for more complex examples with variable sized data. 

Restrictions

CLIP data stores are intended to be used transparently over a computer network.  Thus users should not use memory pointers in a data classes that are expected to cross process boundaries, as they will not be valid when the data is moved to another computer.  Similarly, Standard Template Library classes (STL) and virtual functions should not be used either in this context, as they utilise hidden pointers.

If your application is distributed and you have disparate data structures then it is best practice not to expose them outside a circuit that can be accreted to different processes as the application will fail if all accessors are not co-located within the same address space and this therefore prevents free partitioning of the system.